//
//  FileTableDataSource.m
//  Wi-Fi Party remade-1
//
//  Created by Vieta Ken on 2021/4/16.
//

#import "FileTableDataSource.h"

@implementation FileTableDataSource

-(id)init{
    self=[super init];
    self->files=[[NSArray alloc] init];
    self->documentPath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
    NSFileManager *fileManager=[NSFileManager defaultManager];
    NSError *err=[NSError alloc];
    self->files=[fileManager contentsOfDirectoryAtPath:documentPath error:&err];
    self->lines=self->files.count;
    
    return self;
}

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:@"fileTableViewCellType" forIndexPath:indexPath];
    
    [cell.textLabel setText:self->files[indexPath.row]];
    return cell;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self->lines;
}

@end
